package SwordFingerOffer;

public class Q05_ReplaceSpace {


    public static void main(String[] args) {

    }


    //Java Api
    public String replaceSpace(String s) {
      return  s.replaceAll(" ","%20");
    }

    //StringBuilder
    //String是不可变 不可直接修改
    public String replaceSpace_1(String s) {
       StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            sb.append(s.charAt(i) == ' ' ? "%20" : s.charAt(i));
        }
        return sb.toString();
    }

}
